//
//  UIBarButtonItem+Extension.swift
//  ZYSinaWeibo
//
//  Created by 陟岳 on 16/5/26.
//  Copyright © 2016年 陟岳. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    convenience init(imageName: String, title: String? = nil, target:AnyObject?, action:Selector) {
        
        self.init()
        
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        
        btn.setTitle(title, forState: .Normal)
        
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
        btn.sizeToFit()
        
        self.customView = btn
        
    }

}
